package org.pentaho.cubic.client.menubars;

import org.pentaho.cubic.client.commands.AADemoCommand;
import org.pentaho.cubic.client.commands.AboutCommand;
import org.pentaho.cubic.client.commands.LoginCommand;
import org.pentaho.cubic.client.commands.LogoutCommand;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.MenuItem;

public class CubicMenuBar extends Composite {

	private static CubicMenuBarUiBinder uiBinder = GWT.create(CubicMenuBarUiBinder.class);

	interface CubicMenuBarUiBinder extends UiBinder<Widget, CubicMenuBar> {
	}

	// Menu Bar
	@UiField MenuBar menuBar;
	@UiField MenuBar fileMenu;
	@UiField MenuBar viewMenu;
	@UiField MenuBar toolMenu;
	@UiField MenuBar helpMenu;
	
	// File
	@UiField MenuItem reportNewFileMenu;
	@UiField MenuItem analysisNewFileMenu;
	@UiField MenuItem sourceNewFileMenu;
	@UiField MenuItem openFileMenu;
	@UiField MenuItem saveFileMenu;
	@UiField MenuItem saveasFileMenu;
	@UiField MenuItem printFileMenu;
	@UiField MenuItem editManageFileMenu;
	@UiField MenuItem shareManageFileMenu;
	@UiField MenuItem scheduleManageFileMenu;
	@UiField MenuItem sourcesManageFileMenu;
	@UiField MenuItem propertiesFileMenu;
	@UiField MenuItem logoutFileMenu;
	
	// View
	@UiField MenuItem workspaceViewMenu;
	@UiField MenuItem browserViewMenu;
	@UiField MenuItem refreshViewMenu;
	
	// Tool
	@UiField MenuItem settingsRefreshToolMenu;
	@UiField MenuItem cacheRefreshToolMenu;
	@UiField MenuItem metadataRefreshToolMenu;
	@UiField MenuItem globalRefreshToolMenu;
	@UiField MenuItem mondarinRefreshToolMenu;
	@UiField MenuItem reportingRefreshToolMenu;
	@UiField MenuItem statusToolMenu;
	
	// Help
	@UiField MenuItem helpHelpMenu;
	@UiField MenuItem aboutHelpMenu;
	
	
	// Menu Commands
	Command notYet = new Command(){
		public void execute() {
			Window.alert("Not yet available"); 
		}
	};

	Command loginCommand = new LoginCommand();
	Command aboutHelpCommand = new AboutCommand();		
	
	// Initialize
	public CubicMenuBar() {
		initWidget(uiBinder.createAndBindUi(this));
		
		menuBar.setAutoOpen(false);
		menuBar.setAnimationEnabled(true);
		
		addSeparatorToMenu();
		addCommandToMenu();
		
		//Style
		this.setHeight("30px");
	}
	
	// Add Command To Menu
	private void addCommandToMenu() {
		helpHelpMenu.setCommand(loginCommand);
		aboutHelpMenu.setCommand(aboutHelpCommand);
		logoutFileMenu.setCommand(new LogoutCommand());
		statusToolMenu.setCommand(new AADemoCommand());
	}
	
	
	// Fix Separator Bug in GWT 2.0.3
	private void addSeparatorToMenu() {
		
		// File
		fileMenu.insertSeparator(2);
		fileMenu.insertSeparator(5);
		fileMenu.insertSeparator(7);
		fileMenu.insertSeparator(9);
		fileMenu.insertSeparator(11);
		
		// View
		viewMenu.insertSeparator(2);
		
		// Tool
		toolMenu.insertSeparator(1);
		
		// Help
		helpMenu.insertSeparator(1);
	}
	
}
